<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        {include file="public/link"}
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>分类名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="title" name="name" required="" lay-verify="title" autocomplete="off" class="layui-input">
                            <input type="hidden" id="pid" name="pid" value="{$pid}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>启用|停用</label>
                        <div class="layui-input-inline">
                            <input type="radio" value="1" checked title="启用" name="status"  autocomplete="off" class="layui-input">
                            <input type="radio" value="0"  title="停用" name="status"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
                    </div>
        </form>
        </div>
        </div>
        <script>
            layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //监听提交
                form.on('submit(add)',
                function(data) {

                    console.log(data.field);
                    var field = data.field;
                    //发异步，把数据提交给php
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/cate/add')}",
                        data:{
                            'data':field,
                        },
                        success: function(returnData){
                            console.log('returnData',returnData);
                            if(returnData.code == 200){
                                layer.alert("增加成功", {icon: 6}, function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else{
                                layer.alert("内部错误", {icon: 5}, function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                });
                            }
                        }
                    });

                    return false;
                });
                //动态行业分类
            });
        </script>

    </body>

</html>